#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1e4 + 10;

struct Submission {
    int id, total, full = 0;
    bool only_comp = false;
    int s[6];
    bool st[6] = {false};
    bool operator< (const  Submission& s1) const {
        if (total != s1.total )
            return total > s1.total;
        if (full != s1.full ) 
            return full > s1.full;
        return id < s1.id;
    }
}r[N];

int n, k, m;
int score[6];

inline void solution() {
    cin >> n >> k >> m;
    for (int i = 1; i <= k; i ++ ) 
        cin >> score[i];
    // 离散化 id, index
    unordered_map<int, int> hash;
    int index = 0;
    for (int i = 0; i < m; i ++ ) {
        int idx, qid, sc;
        cin >> idx >> qid >> sc;
        // 这个人已经提交过数据
        if (hash.find(idx) != hash.end()) {
            auto _ = hash[idx];
            // 这道题存在分数
            if (r[_].st[qid]) {
                // 新提交的分数 大于 已经存在的分数 更新分数
                if (r[_].s[qid] < sc) {
                    r[_].total = r[_].total - r[_].s[qid] + sc;
                    r[_].s[qid] = sc;
                    if (sc == score[qid]) 
                        r[_].full ++;
                    r[_].only_comp = false;
                }
            } else {
                if (sc != -1) {
                    r[_].total += sc;
                    r[_].s[qid] = sc;
                    if (sc == score[qid]) 
                        r[_].full ++;
                    r[_].only_comp = false;
                } else {
                    r[_].s[qid] = 0;
                }
                r[_].st[qid] = true;
            }
        } else {
            if (sc != -1) {
                hash[idx] = index;
                r[index].id = idx;
                r[index].total = sc;
                r[index].st[qid] = true;
                if (sc == score[qid]) 
                    r[index].full ++;
                r[index ++ ].s[qid] = sc;
            } else {
                hash[idx] = index;
                r[index].id = idx;
                r[index].total = 0;
                r[index].st[qid] = true;
                r[index].only_comp = true;
                r[index ++ ].s[qid] = 0;
            }
        }
    }
    int t = hash.size();
    vector<Submission> res;
    for (int i = 0; i < t; i ++) 
        if (!r[i].only_comp) res.push_back(r[i]);
    sort(res.begin(), res.end());
    int rank = 1;

    for (int i = 0; i < res.size(); i ++ ) {
        if (res[i].only_comp) continue;
        if (i && res[i].total != res[i - 1].total)
            rank = i + 1;
        printf("%d %05d %d", rank, res[i].id, res[i].total);
        for (int j = 1; j <= k; j ++) 
            if (res[i].st[j])
                printf(" %d", res[i].s[j]);
            else
                printf(" -");
        printf("\n");
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}